package com.zretc.controller;


import com.config.BaseController;
import com.util.CodeMsg;
import com.util.Result;
import com.zretc.pojo.CreditRating;
import com.zretc.pojo.CustomerInfo;
import com.zretc.service.ICreditRatingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * Filename:    CodeMsg.java
 * Description: 客户接口 控制器
 * Copyright:   Copyright (c) 2022-2025 All Rights Reserved.
 * Company:     chinasofti.com Inc.
 * @author:     jiangqi
 * @version:    1.0
 * Create at:   2022-09-07
 *
 * Modification History:
 * Date         Author      Version     Description       tag
 * ------------------------------------------------------------------
 * 2022-09-07      jiangqi      1.0         1.0 Version
 *
 */
@Api("信用评级模块")
@ApiOperation("creditRatController")
@RestController
public class CreditRatingController extends BaseController
{
    @Autowired
    private ICreditRatingService creditRatingService;

    /**
     * 根据身份证查询客户信用信息
     * @return
     */
    @ApiOperation(value = "查询客户信用信息")
    @GetMapping("/findCreditByIdCard")
    public Result<CreditRating> findCreditRating(Long idCard) {
        // 查询客户的状态信息
        CreditRating CreditRating = creditRatingService.selectCreditRatingByCrId(idCard);
        // 返回值
        return Result.success(CreditRating);
    }
    /**
     * 新增用户信用信息
     */
    @ApiOperation(value = "新增用户信用信息")
    @PostMapping("/addCreditRating")
    public Result addCreditRating(@Valid CreditRating creditRating)
    {
        // 插入数据是否成功
        int i = creditRatingService.insertCreditRating(creditRating);
        // 根据返回值判断
        if (i == 1) {
            return Result.success(i);
        }else{
            return Result.error(CodeMsg.INSERT_INFO);
        }

    }
//
//    /**
//     * 获取【请填写功能名称】详细信息
//     */
//    @PreAuthorize("@ss.hasPermi('system:rating:query')")
//    @GetMapping(value = "/{crId}")
//    public AjaxResult getInfo(@PathVariable("crId") Long crId)
//    {
//        return AjaxResult.success(creditRatingService.selectCreditRatingByCrId(crId));
//    }
//

    /**
     * 修改用户信用信息
     */
    @ApiOperation(value = "修改用户信用信息")
    @PostMapping("/editCreditRating")
    public Result edit(@RequestBody CreditRating creditRating)
    {
        // 个人情况
        Long score1=creditRating.getPersonMessageAge()+creditRating.getPersonMessageEdu()+creditRating.getPersonMessageHealth();
        // 家庭情况
        Long score2=creditRating.getFamilyMessageMarry()+creditRating.getFamilyMessageFamilycount()+creditRating.getFamilyMessageAppraise()+creditRating.getFamilyMessageHouse();
        // 财务情况
        Long score3=creditRating.getFinanceMessageDebtratio()+creditRating.getFinanceMessageJzc()+creditRating.getFinanceMessageRj()+creditRating.getFinanceMessageDw();
        // 职业情况
        Long score4=creditRating.getProfessionalMessageType()+creditRating.getProfessionalMessageEconomic()+creditRating.getProfessionalMessageProspects()+creditRating.getProfessionalMessageYear()+creditRating.getProfessionalMessageJobs()+creditRating.getProfessionalMessageTitle();
        // 个人信用记录
        Long score5=creditRating.getPersonalCredit();
        // 保险情况
        Long score6=creditRating.getHousingProvidentFund()+creditRating.getSocialInsurance();
        // 总分
        creditRating.setTotal_score(score1+score2+score3+score4+score5+score6);
        // 修改数据是否成功
        int i = creditRatingService.updateCreditRating(creditRating);
        // 根据返回值判断
        if (i == 1) {
            return Result.success(i);
        }else{
            return Result.error(CodeMsg.INSERT_INFO);
        }

    }

//    /**
//     * 删除【请填写功能名称】
//     */
//    @PreAuthorize("@ss.hasPermi('system:rating:remove')")
//    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
//	@DeleteMapping("/{crIds}")
//    public AjaxResult remove(@PathVariable Long[] crIds)
//    {
//        return toAjax(creditRatingService.deleteCreditRatingByCrIds(crIds));
//    }
}
